#include "MyTimer.h"
#include "PKB.h"
#include <intrin.h>
#include <time.h>

MyTimer::MyTimer()
{
	srand ( time(NULL) );
	debug=0;
	ifstream inFile("time.txt");
	string temp;
	getline(inFile,temp,'\n');
	double timeLimit = atof(temp.c_str());
	getline(inFile,temp,'\n');
	stepSize = atoi(temp.c_str());
	getline(inFile,temp,'\n');
	debug = atoi(temp.c_str());
	clocks_per_sec = calculateClocksPerSec();
	clockCycleLimit = (unsigned __int64)((double)clocks_per_sec*timeLimit);
	inFile.close();
}
int MyTimer::random(int max)
{
	return rand() % max;
}
unsigned __int64 MyTimer::calculateClocksPerSec()
{
	clock_t start=clock();
	clock_t end=clock();
	unsigned __int64 st = GetCpuClock();
	
	
	while ((end-start)/CLOCKS_PER_SEC<2.0)
	{
		end = clock();
	}
	unsigned __int64 et = GetCpuClock();
	return (et-st)/2;
}

int MyTimer::findMin(vector<unsigned __int64> v)
{
	int pos=-1;
	unsigned __int64 posValue=std::numeric_limits<unsigned __int64>::max();
	for (int i=0; i<v.size();i++)
	{
		if (v[i]>0&&v[i]<posValue)
		{
			posValue=v[i];
			pos=i;
		}
	}
	return pos;
}

inline unsigned __int64 MyTimer::GetCpuClock()
{
	return __rdtsc();
}

inline unsigned __int64 MyTimer::GetCpuClock2()
{


    // Counter
    struct { unsigned int low, high; } counter;

    // Use RDTSC instruction to get clocks count
    __asm push EAX
    __asm push EDX
    __asm __emit 0fh __asm __emit 031h // RDTSC
    __asm mov counter.low, EAX
    __asm mov counter.high, EDX
    __asm pop EDX
    __asm pop EAX

    // Return result
    return *(unsigned __int64 *)(&counter);

}

unsigned __int64 MyTimer::calls()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0||v1.size()==1||v2.size()==1)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _callshandle->handleCalls(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::callsV2()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
		
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_callshandle->handleCalls(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}


unsigned __int64 MyTimer::callsV3()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter1=0;
				while (j!=c.end()&&counter1<stepSize)
				{
					j++;
					counter1++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_callshandle->handleCalls(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::callsV4()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	int setSize = c.size();
	if (c.size()==0||c.size()==1)
		return 0;
	while (true)
	{
		pos1=random(setSize);
		pos2=random(setSize);
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_callshandle->handleCalls(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::follows()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _followshandle->RetrieveFollows(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::followsV2()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_followshandle->RetrieveFollows(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::followsV3()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_followshandle->RetrieveFollows(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::followsV4()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	int setSize = c.size();
	if (c.size()==0||c.size()==1)
		return 0;
	while (true)
	{
		pos1=random(setSize);
		pos2=random(setSize);
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_followshandle->RetrieveFollows(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::sibling()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _siblinghandle->RetrieveSibling(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::siblingV2()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
	//	for (set<int>::iterator j=c.begin();j != c.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_siblinghandle->RetrieveSibling(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::siblingV3()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_siblinghandle->RetrieveSibling(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::parents()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _parenthandle->RetrieveParent(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::parentsV2()
{
	if (PKB::shortcutTable.GetAllWhile().size()==0&&PKB::shortcutTable.GetAllIf().size()==0)
		return 0;
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
			//v2.clear();
			v1.push_back(*i);
			//v2.push_back(*j);
			st = GetCpuClock();
			_parenthandle->RetrieveParent(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::parentsV3()
{
	if (PKB::shortcutTable.GetAllWhile().size()==0&&PKB::shortcutTable.GetAllIf().size()==0)
		return 0;
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_parenthandle->RetrieveParent(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::parentsV4()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	int setSize = c.size();
	if (c.size()==0||c.size()==1||(PKB::shortcutTable.GetAllWhile().size()+PKB::shortcutTable.GetAllIf().size()==0))
		return 0;
	while (true)
	{
		pos1=random(setSize);
		pos2=random(setSize);
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_parenthandle->RetrieveParent(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}


unsigned __int64 MyTimer::next()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _nexthandle->RetrieveNext(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::nextV2()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
	//	for (set<int>::iterator j=c.begin();j != c.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_nexthandle->RetrieveNext(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::nextV3()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_nexthandle->RetrieveNext(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::nextV4()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	int setSize = c.size();
	if (c.size()==0||c.size()==1)
		return 0;
	while (true)
	{
		pos1=random(setSize);
		pos2=random(setSize);
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_nexthandle->RetrieveNext(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::affects()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _affectshandle->RetrieveAffects(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::affectsV2()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
			//v2.clear();
			v1.push_back(*i);
			//v2.push_back(*j);
			st = GetCpuClock();
			_affectshandle->RetrieveAffects(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::affectsV3()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_affectshandle->RetrieveAffects(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::callsT()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _callshandle->handleCallsT(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::callsTV2()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
	//	for (set<int>::iterator j=c.begin();j != c.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
	//		v2.clear();
			v1.push_back(*i);
	//		v2.push_back(*j);
			st = GetCpuClock();
			_callshandle->handleCallsT(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::callsTV3()
{
	set<int> c = PKB::procTable.GetAllProcIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_callshandle->handleCallsT(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::followsT()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _followshandle->RetrieveTransitiveFollows(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::followsTV2()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
	//	for (set<int>::iterator j=c.begin();j != c.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
	//		v2.clear();
			v1.push_back(*i);
	//		v2.push_back(*j);
			st = GetCpuClock();
			_followshandle->RetrieveTransitiveFollows(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::followsTV3()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_followshandle->RetrieveTransitiveFollows(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::parentsT()
{
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _parenthandle->RetrieveTransitiveParent(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::parentsTV2()
{
	if (PKB::shortcutTable.GetAllWhile().size()==0&&PKB::shortcutTable.GetAllIf().size()==0)
		return 0;
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
	//	for (set<int>::iterator j=c.begin();j != c.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
	//		v2.clear();
			v1.push_back(*i);
	//		v2.push_back(*j);
			st = GetCpuClock();
			_parenthandle->RetrieveTransitiveParent(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::parentsTV3()
{
	if (PKB::shortcutTable.GetAllWhile().size()==0&&PKB::shortcutTable.GetAllIf().size()==0)
		return 0;
	set<int> c = PKB::shortcutTable.GetAllStatement();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_parenthandle->RetrieveTransitiveParent(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::nextT()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _nexthandle->RetrieveTransitiveNext(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}


unsigned __int64 MyTimer::nextTV2()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_nexthandle->RetrieveTransitiveNext(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::nextTV3()
{
	set<int> c = PKB::shortcutTable.GetAllProgramLine();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_nexthandle->RetrieveTransitiveNext(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::affectsT()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _affectshandle->RetrieveTransitiveAffects(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::affectsTV2()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c.begin(),c.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c.size()==0)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		//for (set<int>::iterator j=c.begin();j != c.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
			//v2.push_back(*j);
			st = GetCpuClock();
			_affectshandle->RetrieveTransitiveAffects(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::affectsTV3()
{
	set<int> c = PKB::shortcutTable.GetAllAssign();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c.begin(),c.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c.begin(),c.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c.size()==0||c.size()==1)
		return 0;
	for (set<int>::iterator i=c.begin();i != c.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c.begin();j != c.end();)
		{
			
			if (stepSize==0)
			{
				j=c.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_affectshandle->RetrieveTransitiveAffects(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesS()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _modifieshandle->FetchValidModifiesStatementVar(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::modifiesSV2()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		//for (set<int>::iterator j=c2.begin();j != c2.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_modifieshandle->FetchValidModifiesStatementVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesSV3()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_modifieshandle->FetchValidModifiesStatementVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesSV4()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_modifieshandle->FetchValidModifiesStatementVar(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesP()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _modifieshandle->FetchValidModifiesProcedureVar(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::modifiesPV2()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		//for (set<int>::iterator j=c2.begin();j != c2.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_modifieshandle->FetchValidModifiesProcedureVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesPV3()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_modifieshandle->FetchValidModifiesProcedureVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::modifiesPV4()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_modifieshandle->FetchValidModifiesProcedureVar(v3,v4);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesS()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _useshandle->FetchValidUsesStatementVar(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::usesSV2()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		//for (set<int>::iterator j=c2.begin();j != c2.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_useshandle->FetchValidUsesStatementVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesSV3()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_useshandle->FetchValidUsesStatementVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesSV4()
{
	set<int> c1 = PKB::shortcutTable.GetAllStatement();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_useshandle->FetchValidUsesStatementVar(v1,v2);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesP()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _useshandle->FetchValidUsesProcedureVar(v1,v2);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::usesPV2()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
	//	for (set<int>::iterator j=c2.begin();j != c2.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
	//		v2.clear();
			v1.push_back(*i);
	//		v2.push_back(*j);
			st = GetCpuClock();
			_useshandle->FetchValidUsesProcedureVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesPV3()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_useshandle->FetchValidUsesProcedureVar(v1,v2);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::usesPV4()
{
	set<int> c1 = PKB::procTable.GetAllProcIndex();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_useshandle->FetchValidUsesProcedureVar(v1,v2);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternA()
{
	set<int> c1 = PKB::shortcutTable.GetAllAssign();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	string s = "x";
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _patternhandle.evaluateAssignV2(v1,v2,_patternhandle.LEFT_VARIABLE,s,_patternhandle.RIGHT_SUB_EXPRESSION);
	unsigned __int64 et = GetCpuClock();
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::patternAV2()
{
	set<int> c1 = PKB::shortcutTable.GetAllAssign();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	string s = "x";
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		//for (set<int>::iterator j=c2.begin();j != c2.end();j++)
		//{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_patternhandle.evaluateAssignV2(v1,v2,_patternhandle.LEFT_VARIABLE,s,_patternhandle.RIGHT_SUB_EXPRESSION);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternAV3()
{
	set<int> c1 = PKB::shortcutTable.GetAllAssign();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	string s = "x";
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_patternhandle.evaluateAssignV2(v1,v2,_patternhandle.LEFT_VARIABLE,s,_patternhandle.RIGHT_SUB_EXPRESSION);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternAV4()
{
	set<int> c1 = PKB::shortcutTable.GetAllAssign();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	string s = "x";
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_patternhandle.evaluateAssignV2(v3,v4,_patternhandle.LEFT_VARIABLE,s,_patternhandle.RIGHT_SUB_EXPRESSION);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternI()
{
	set<int> c1 = PKB::shortcutTable.GetAllIf();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::patternIV2()
{
	set<int> c1 = PKB::shortcutTable.GetAllIf();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
	//	for (set<int>::iterator j=c2.begin();j != c2.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
		//	v2.clear();
			v1.push_back(*i);
		//	v2.push_back(*j);
			st = GetCpuClock();
			_patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternIV3()
{
	set<int> c1 = PKB::shortcutTable.GetAllIf();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternIV4()
{
	set<int> c1 = PKB::shortcutTable.GetAllIf();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_patternhandle.evaluateWhileIfControlVariableV2(v3,v4,_patternhandle.LEFT_VARIABLE);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternW()
{
	set<int> c1 = PKB::shortcutTable.GetAllWhile();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	if (v1.size()==0||v2.size()==0)
		return 0;
	unsigned __int64 st = GetCpuClock();
	vector<vector<int>> result = _patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
	unsigned __int64 et = GetCpuClock();
	if (result.size()==0||result[0].size()==0)
		return 0;
	//cout << "time elapsed: " << et-st << endl;
	return (et-st)/(v1.size()*v2.size())+1;
}

unsigned __int64 MyTimer::patternWV2()
{
	set<int> c1 = PKB::shortcutTable.GetAllWhile();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	vector<int> v2(c2.begin(),c2.end());
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	if (c1.size()==0||c2.size()==0)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
	//	for (set<int>::iterator j=c2.begin();j != c2.end();j++)
	//	{
			//if (v1.size()>0)
			v1.clear();
			//if (v2.size()>0);
	//		v2.clear();
			v1.push_back(*i);
	//		v2.push_back(*j);
			st = GetCpuClock();
			_patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=c2.size();
			if (timer>=clockCycleLimit)
				break;
	//	}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternWV3()
{
	set<int> c1 = PKB::shortcutTable.GetAllWhile();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1;//(c.begin(),c.end());
	//vector<int> v2(c2.begin(),c2.end());
	vector<int> v2;
	if (stepSize==0)
	{
		vector<int> temp(c2.begin(),c2.end());
		v2=temp;
	}
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
//	vector<vector<int>> result;
	if (c1.size()==0||c2.size()==1)
		return 0;
	for (set<int>::iterator i=c1.begin();i != c1.end();i++)
	{
		v1.clear();
		v1.push_back(*i);
		for (set<int>::iterator j=c2.begin();j != c2.end();)
		{
			
			if (stepSize==0)
			{
				j=c2.end();
			}
			else
			{
				// 0 1 2 3 4
				v2.clear();
				set<int>::iterator k=j;
				int counter=0;
				while (j!=c2.end()&&counter<stepSize)
				{
					j++;
					counter++;
				}
				v2.insert(v2.begin(),k,j);
			}
			st = GetCpuClock();
			_patternhandle.evaluateWhileIfControlVariableV2(v1,v2,_patternhandle.LEFT_VARIABLE);
			et = GetCpuClock();
			timer+=(et-st);
			counter+=v2.size();
			if (timer>=clockCycleLimit)
				break;
		}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

unsigned __int64 MyTimer::patternWV4()
{
	set<int> c1 = PKB::shortcutTable.GetAllWhile();
	set<int> c2 = PKB::varTable.GetAllVarIndex();
	vector<int> v1(c1.begin(),c1.end());
	vector<int> v2(c2.begin(),c2.end());
	vector<int> v3;
	vector<int> v4;
	unsigned __int64 st=0;
	unsigned __int64 et=0;
	unsigned __int64 timer=0;
	unsigned __int64 counter=0;
	//vector<vector<int>> result;
	int pos1=0;
	int pos2=0;
	if (c1.size()==0||c2.size()==0)
		return 0;
	while (true)
	{
		pos1=random(v1.size());
		pos2=random(v2.size());
		v3.clear();
		v4.clear();
		v3.push_back(v1[pos1]);
		v4.push_back(v2[pos2]);
		st = GetCpuClock();
		_patternhandle.evaluateWhileIfControlVariableV2(v3,v4,_patternhandle.LEFT_VARIABLE);
		et = GetCpuClock();
		timer+=(et-st);
		counter+=1;
		if (timer>=clockCycleLimit)
			break;
		//}
	}
	//cout << "time elapsed: " << et-st << endl;
	return (timer)/(counter)+1;
}

vector<string> MyTimer::returnRelation()
{
	return relation;
}

vector<unsigned __int64> MyTimer::returnResult()
{
	return result;
}

void MyTimer::process()
{
	/*
	unsigned __int64 st1 = GetCpuClock();
	processV1();
	unsigned __int64 et1 = GetCpuClock();
	unsigned __int64 st2 = GetCpuClock();
	processV2();
	unsigned __int64 et2 = GetCpuClock();
	
	unsigned __int64 st3 = GetCpuClock();
	processV3();
	unsigned __int64 et3 = GetCpuClock();
	*/
	if (debug==1)
	{
	//	unsigned __int64 st4 = GetCpuClock();
	//	processV4();
	//	unsigned __int64 et4 = GetCpuClock();
		unsigned __int64 st5 = GetCpuClock();
		processV5();
		unsigned __int64 et5 = GetCpuClock();
	//	cout << "process 4 took: " << et4-st4 << endl;
	//	cout << "time in secs: " << ((double)(et4-st4))/clocks_per_sec << endl;
		
		//cout << "process 4 took: " << et5-st5 << endl;
		//cout << "time in secs: " << ((double)(et5-st5))/clocks_per_sec << endl;
	}
	else if (debug==0)
	{
		//processV4();
		processV5();
	}
	else if (debug==2)
	{
	//	clock_t begin1=clock();
	//	processV4();
	//	clock_t end1=clock();
		clock_t begin2=clock();
		processV5();
		clock_t end2=clock();
	//	cout << "Time elapsed: " << (end1-begin1) / ((double) CLOCKS_PER_SEC) << " sec"<< endl;
		
		//cout << "Time elapsed: " << (end2-begin2) / ((double) CLOCKS_PER_SEC) << " sec"<< endl;
	}
	//cout << "clocks per sec: " << clocks_per_sec << endl;
	/*
	cout << "process 1 took: " << et1-st1 << endl;
	cout << "time in secs: " << ((double)(et1-st1))/clocks_per_sec << endl;
	cout << "process 2 took: " << et2-st2 << endl;
	cout << "time in secs: " << ((double)(et2-st2))/clocks_per_sec << endl;
	
	cout << "process 3 took: " << et3-st3 << endl;
	cout << "time in secs: " << ((double)(et3-st3))/clocks_per_sec << endl;
	*/
	
}

void MyTimer::processV1()
{
	result.clear();
	relation.clear();

	string callr = "CALLS";
	relation.push_back(callr);
	result.push_back(calls());

	string followr = "FOLLOWS";
	relation.push_back(followr);
	result.push_back(follows());

	string parentr = "PARENT";
	relation.push_back(parentr);
	result.push_back(parents());

	string nextr = "NEXT";
	relation.push_back(nextr);
	result.push_back(next());

	string affectr = "AFFECTS";
	relation.push_back(affectr);
	result.push_back(affects());

	string callrT = "CALLS_T";
	relation.push_back(callrT);
	result.push_back(callsT());

	string followsrT = "FOLLOWS_T";
	relation.push_back(followsrT);
	result.push_back(followsT());

	string parentrT = "PARENT_T";
	relation.push_back(parentrT);
	result.push_back(parentsT());

	string nextrT = "NEXT_T";
	relation.push_back(nextrT);
	result.push_back(nextT());

	string affectsrT = "AFFECTS_T";
	relation.push_back(affectsrT);
	result.push_back(affectsT());

	string modifiesSr = "MODIFIES_S";
	relation.push_back(modifiesSr);
	result.push_back(modifiesS());

	string modifiesPr = "MODIFIES_P";
	relation.push_back(modifiesPr);
	result.push_back(modifiesP());

	string usesSr = "USES_S";
	relation.push_back(usesSr);
	result.push_back(usesS());

	string usesPr = "USES_P";
	relation.push_back(usesPr);
	result.push_back(usesP());

	string patternAr = "PATTERN_A";
	relation.push_back(patternAr);
	result.push_back(patternA());

	string patternIr = "PATTERN_I";
	relation.push_back(patternIr);
	result.push_back(patternI());

	string patternWr = "PATTERN_W";
	relation.push_back(patternWr);
	result.push_back(patternW());

	string siblingr = "SIBLING";
	relation.push_back(siblingr);
	result.push_back(sibling());
	int min = findMin(result);
	unsigned __int64 factor = result[min]/this->SMALLEST_VALUE;
	for (int i=0; i<result.size();i++)
	{
		if (result[i]>0)
			result[i]=result[i]/factor;
	}
	
	//cout << findMin(result) << endl;
	
	for (int i=0; i<result.size(); i++)
	{
		//cout << relation[i] << ": " << result[i] << endl;
	}
	
}

void MyTimer::processV2()
{
	result.clear();
	relation.clear();

	string callr = "CALLS";
	relation.push_back(callr);
	result.push_back(callsV2());

	string followr = "FOLLOWS";
	relation.push_back(followr);
	result.push_back(followsV2());

	string parentr = "PARENT";
	relation.push_back(parentr);
	result.push_back(parentsV2());

	string nextr = "NEXT";
	relation.push_back(nextr);
	result.push_back(nextV2());

	string affectr = "AFFECTS";
	relation.push_back(affectr);
	result.push_back(affectsV2());

	string callrT = "CALLS_T";
	relation.push_back(callrT);
	result.push_back(callsTV2());

	string followsrT = "FOLLOWS_T";
	relation.push_back(followsrT);
	result.push_back(followsTV2());

	string parentrT = "PARENT_T";
	relation.push_back(parentrT);
	result.push_back(parentsTV2());

	string nextrT = "NEXT_T";
	relation.push_back(nextrT);
	result.push_back(nextTV2());

	string affectsrT = "AFFECTS_T";
	relation.push_back(affectsrT);
	result.push_back(affectsTV2());

	string modifiesSr = "MODIFIES_S";
	relation.push_back(modifiesSr);
	result.push_back(modifiesSV2());

	string modifiesPr = "MODIFIES_P";
	relation.push_back(modifiesPr);
	result.push_back(modifiesPV2());

	string usesSr = "USES_S";
	relation.push_back(usesSr);
	result.push_back(usesSV2());

	string usesPr = "USES_P";
	relation.push_back(usesPr);
	result.push_back(usesPV2());

	string patternAr = "PATTERN_A";
	relation.push_back(patternAr);
	result.push_back(patternAV2());

	string patternIr = "PATTERN_I";
	relation.push_back(patternIr);
	result.push_back(patternIV2());

	string patternWr = "PATTERN_W";
	relation.push_back(patternWr);
	result.push_back(patternWV2());

	string siblingr = "SIBLING";
	relation.push_back(siblingr);
	result.push_back(siblingV2());

	int min = findMin(result);
	unsigned __int64 factor = result[min]/this->SMALLEST_VALUE;
	for (int i=0; i<result.size();i++)
	{
		if (result[i]>0)
			result[i]=result[i]/factor;
	}
	
	//cout << findMin(result) << endl;
	
	for (int i=0; i<result.size(); i++)
	{
		//cout << relation[i] << ": " << result[i] << endl;
	}
	
}


void MyTimer::processV3()
{
	result.clear();
	relation.clear();

	string callr = "CALLS";
	relation.push_back(callr);
	result.push_back(callsV3());

	string followr = "FOLLOWS";
	relation.push_back(followr);
	result.push_back(followsV3());

	
	string parentr = "PARENT";
	relation.push_back(parentr);
	result.push_back(parentsV3());
	
	string nextr = "NEXT";
	relation.push_back(nextr);
	result.push_back(nextV3());
	
	string affectr = "AFFECTS";
	relation.push_back(affectr);
	result.push_back(affectsV3());

	string callrT = "CALLS_T";
	relation.push_back(callrT);
	result.push_back(callsTV3());

	string followsrT = "FOLLOWS_T";
	relation.push_back(followsrT);
	result.push_back(followsTV3());

	string parentrT = "PARENT_T";
	relation.push_back(parentrT);
	result.push_back(parentsTV3());

	string nextrT = "NEXT_T";
	relation.push_back(nextrT);
	result.push_back(nextTV3());

	string affectsrT = "AFFECTS_T";
	relation.push_back(affectsrT);
	result.push_back(affectsTV3());

	string modifiesSr = "MODIFIES_S";
	relation.push_back(modifiesSr);
	result.push_back(modifiesSV3());

	string modifiesPr = "MODIFIES_P";
	relation.push_back(modifiesPr);
	result.push_back(modifiesPV3());

	string usesSr = "USES_S";
	relation.push_back(usesSr);
	result.push_back(usesSV3());

	string usesPr = "USES_P";
	relation.push_back(usesPr);
	result.push_back(usesPV3());

	string patternAr = "PATTERN_A";
	relation.push_back(patternAr);
	result.push_back(patternAV3());

	string patternIr = "PATTERN_I";
	relation.push_back(patternIr);
	result.push_back(patternIV3());

	string patternWr = "PATTERN_W";
	relation.push_back(patternWr);
	result.push_back(patternWV3());

	string siblingr = "SIBLING";
	relation.push_back(siblingr);
	result.push_back(siblingV3());
	
	int min = findMin(result);
	unsigned __int64 factor = result[min]/this->SMALLEST_VALUE;
	for (int i=0; i<result.size();i++)
	{
		if (result[i]>0)
			result[i]=result[i]/factor;
	}
	
	//cout << findMin(result) << endl;
	
	for (int i=0; i<result.size(); i++)
	{
		//cout << relation[i] << ": " << result[i] << endl;
	}
	
}

void MyTimer::processV4()
{
	result.clear();
	relation.clear();

	string callr = "CALLS";
	relation.push_back(callr);
	result.push_back(callsV3());
	
	string followr = "FOLLOWS";
	relation.push_back(followr);
	result.push_back(followsV3());

	
	string parentr = "PARENT";
	relation.push_back(parentr);
	result.push_back(parentsV3());
	
	string nextr = "NEXT";
	relation.push_back(nextr);
	result.push_back(nextV3());
	
	string modifiesSr = "MODIFIES_S";
	relation.push_back(modifiesSr);
	result.push_back(modifiesSV3());

	string modifiesPr = "MODIFIES_P";
	relation.push_back(modifiesPr);
	result.push_back(modifiesPV3());

	string usesSr = "USES_S";
	relation.push_back(usesSr);
	result.push_back(usesSV3());

	string usesPr = "USES_P";
	relation.push_back(usesPr);
	result.push_back(usesPV3());

	string patternAr = "PATTERN_A";
	relation.push_back(patternAr);
	result.push_back(patternAV3());

	string patternIr = "PATTERN_I";
	relation.push_back(patternIr);
	result.push_back(patternIV3());

	string patternWr = "PATTERN_W";
	relation.push_back(patternWr);
	result.push_back(patternWV3());

	

	int min = findMin(result);
	unsigned __int64 factor = result[min]/this->SMALLEST_VALUE;
	for (int i=0; i<result.size();i++)
	{
		if (result[i]>0)
			result[i]=result[i]/factor;
	}

	string callrT = "CALLS_T";
	relation.push_back(callrT);
	result.push_back(result[0]*result[0]);

	string followsrT = "FOLLOWS_T";
	relation.push_back(followsrT);
	result.push_back(result[1]*result[1]);

	string siblingr = "SIBLING";
	relation.push_back(siblingr);
	result.push_back(result[12]*2);

	string parentrT = "PARENT_T";
	relation.push_back(parentrT);
	result.push_back(result[2]*result[2]);

	//8= 2*2*2
	// first 2 is due to summation , sum(1:n)= (n*(n+1))/2
	// second 2 is to take average
	// third 2 is to compensate for early terimination, in average case
	string nextrT = "NEXT_T";
	relation.push_back(nextrT);
	result.push_back(result[3]*
		(PKB::shortcutTable.GetAllProgramLine().size()*(PKB::shortcutTable.GetAllProgramLine().size()+1))/8
		);
	

	string affectr = "AFFECTS";
	relation.push_back(affectr);
	//result.push_back(result[15]*result[4]*result[6]/2);
	result.push_back(PKB::shortcutTable.GetAllAssign().size()*result[15]*result[8]/(2*PKB::shortcutTable.GetAllProgramLine().size()));

	string affectsrT = "AFFECTS_T";
	relation.push_back(affectsrT);
	result.push_back(result[16]*2);

	//string nextrT2 = "NEXT_T2";
	//relation.push_back(nextrT2);
	//result.push_back(nextTV3()/factor);
	
	//cout << findMin(result) << endl;
	if (debug==1)
	{
		for (int i=0; i<result.size(); i++)
		{
		//	cout << relation[i] << ": " << result[i] << endl;
		}
	}
	
}

void MyTimer::processV5()
{
	result.clear();
	relation.clear();

	string callr = "CALLS";
	relation.push_back(callr);
	result.push_back(callsV4());
	
	string followr = "FOLLOWS";
	relation.push_back(followr);
	result.push_back(followsV4());

	
	string parentr = "PARENT";
	relation.push_back(parentr);
	result.push_back(parentsV4());
	
	string nextr = "NEXT";
	relation.push_back(nextr);
	result.push_back(nextV4());
	
	string modifiesSr = "MODIFIES_S";
	relation.push_back(modifiesSr);
	result.push_back(modifiesSV4());

	string modifiesPr = "MODIFIES_P";
	relation.push_back(modifiesPr);
	result.push_back(modifiesPV4());

	string usesSr = "USES_S";
	relation.push_back(usesSr);
	result.push_back(usesSV4());

	string usesPr = "USES_P";
	relation.push_back(usesPr);
	result.push_back(usesPV4());

	string patternAr = "PATTERN_A";
	relation.push_back(patternAr);
	result.push_back(patternAV4());

	string patternIr = "PATTERN_I";
	relation.push_back(patternIr);
	result.push_back(patternIV4());

	string patternWr = "PATTERN_W";
	relation.push_back(patternWr);
	result.push_back(patternWV4());

	

	int min = findMin(result);
	unsigned __int64 factor = result[min]/this->SMALLEST_VALUE;
	for (int i=0; i<result.size();i++)
	{
		if (result[i]>0)
			result[i]=result[i]/factor;
	}

	string callrT = "CALLS_T";
	relation.push_back(callrT);
	result.push_back(result[0]*result[0]);

	string followsrT = "FOLLOWS_T";
	relation.push_back(followsrT);
	result.push_back(result[1]*result[1]);

	string siblingr = "SIBLING";
	relation.push_back(siblingr);
	result.push_back(result[12]*2);

	string parentrT = "PARENT_T";
	relation.push_back(parentrT);
	result.push_back(result[2]*result[2]);

	//8= 2*2*2
	// first 2 is due to summation , sum(1:n)= (n*(n+1))/2
	// second 2 is to take average
	// third 2 is to compensate for early terimination, in average case
	string nextrT = "NEXT_T";
	relation.push_back(nextrT);
	result.push_back(result[3]*
		(PKB::shortcutTable.GetAllProgramLine().size()*(PKB::shortcutTable.GetAllProgramLine().size()+1))/8
		);
	

	string affectr = "AFFECTS";
	relation.push_back(affectr);
	//result.push_back(result[15]*result[4]*result[6]/2);
	result.push_back(PKB::shortcutTable.GetAllAssign().size()*result[15]*result[8]/(2*PKB::shortcutTable.GetAllProgramLine().size()));

	string affectsrT = "AFFECTS_T";
	relation.push_back(affectsrT);
	result.push_back(result[16]*2);

	//string nextrT2 = "NEXT_T2";
	//relation.push_back(nextrT2);
	//result.push_back(nextTV3()/factor);
	
	//cout << findMin(result) << endl;
	if (debug==1)
	{
		for (int i=0; i<result.size(); i++)
		{
			//cout << relation[i] << ": " << result[i] << endl;
		}
	}
	
}

MyTimer::~MyTimer()
{
}